(function(){
    App.modules.SysProc = function(){
        var breadcrumb = new App.models.Breadcrumb({
            prefix: [
                {text: '状态管理', anchor: '/sysproc'}
            ],
            curr: '系统进程'
        });
        var SysProcTableOpts = {
            el: '#sysproc .sysproc-list',
            columns: [
                {field: 'name',     title: '进程名称'},
                {
                    field: 'psStr',
                    title: '匹配字符串',
                    formatter: function(value, row, index){
                        return widthRestrictedPopover(value, value, 'wordcut-240');
                    }
                },
                {
                    field: 'desc',
                    title: '描述'
                },
                {
                    field: 'operation', 
                    title: '操作',
                    class: 'operate-col',
                    formatter: function(value, row, index){
                        return '<span class="btn-del-inline"><i class="fa fa-trash-o"></i></span>';
                    }
                },
            ],
            opts: {
                url: App.apiList.sysproc + '/query',
                toolbar: '#sysproc .toolbar',
            },
        };
        var SysProcTable = App.views.BaseTableView.extend({});

        var MainView = Backbone.View.extend({
            // el与initialize一样是bk的关键字, 不能重命名为其它
            el: '#page-cnt',
            template:  _.template($("#tpl-sysproc").html()),
            events: {},
            initialize: function() {
                // backbone的事件总线机制, 子视图之间可以由总线上报到主视图再与其他子视图通信
                this.eventBus = _.extend({}, Backbone.Events);
                // 创建面包屑视图
                this.breadcrumbView = new App.views.BreadcrumbView({model: breadcrumb});
                this.$el.html(this.template());

                this.sysprocModel = new App.models.SysProc();
                
                this.sysprocTable = new SysProcTable(Object.assign(
                    {
                        eventBus: this.eventBus,
                        dataModel: this.sysprocModel
                    },
                    SysProcTableOpts
                ));

                this.watch();
            },
            watch: function(){
                var _self = this;
                this.listenTo(_self.sysprocModel, 'requestSuccess', function(){
                    _self.sysprocTable.$el.bootstrapTable('refresh');
                });
            }
        });
        var mainView = new MainView();
    }
})();